<?php
define("mTABLE", "tbl_content_d6aaea0289de42d0105bf8f005112faa");
class content_model extends FlexiGrid_Model {

    function __construct()
    {
        parent::__construct();
        
    }
    function getmulti(){
//        $this->db
//        ->on_duplicate_update("a",array("v"),array("name"=>"asdasd","v"=>time()));
//        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
//        if($count>1) return true;
//        return false;
        $where=array("Lock"=>1);
        $query=$this->db
                ->where($where)
                //->or_where("ID <","21`'",true,"open")
                //->where("ID >",22,true,"close")    
                ->bracket('open')
                ->where("ID <",21)
                ->or_where("ID >",22)
                ->bracket('close')
                ->get('adp_settings'); 
        $this->output->enable_profiler(TRUE);
        return $query->result();
        
//$this->db->where('groups_members.group_id', $this->session->userdata('group_id'));
//$this->db->where('groups_members.join_date <=', $end_date);
//$this->db->bracket('open');
//$this->db->or_where('groups_members.resign_date', NULL);
//$this->db->where('groups_members.resign_date >=', $start_date);
//$this->db->bracket('close');
//$this->db->join('groups_members', 'groups_members.member_id = members.user_id');
//$this->db->order_by('last_name', 'asc');
//$query = $this->db->get('members'); 
        
    }
    function get($ID){
        $where=array('ID_'.md5("kID")=>$ID);
        $query=$this->db->get_where(mTABLE, $where); 
        return $query->result();
    }
    
    function insert($params){
        $this->db->set('Insert_'.md5("kInsert"), 'NOW()', FALSE);
        $this->db->insert(mTABLE, $params); 
        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return true;
        return false;
    }
    function delete($ID){
        $this->db->set('Delete_'.md5("kDelete"), 'NOW()', FALSE);
        $where=array('ID_'.md5("kID")=>$ID);
        $this->db->where($where);
        $this->db->update('tbl_content'); 
        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return true;
        return false;
    }
    function retore($ID){
        $this->db->set('Delete_'.md5("kDelete"), 'NULL', FALSE);
        $where=array('ID_'.md5("kID")=>$ID);
        $this->db->where($where);
        $this->db->update('tbl_content'); 
        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return true;
        return false;
    }
    function update($ID,$params){
        $this->db->set('Update_'.md5("kUpdate"), 'NOW()', FALSE);
        $this->db->where('ID_'.md5("kID"), $ID);
        $this->db->update(mTABLE, $params); 
        $count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return true;
        return false;
    }
    function FlexiGridData(){
        $configs["strQuery"]="
            SELECT SQL_CALC_FOUND_ROWS `".mTABLE."`.*
            FROM `".mTABLE."`
            ";
        $configs["strWhere"]="
            WHERE True
            ";
        if(isset($_SESSION["ADP"][CCTRL]) && $_SESSION["ADP"][CCTRL]["display"]==0){
            $configs["strWhere"].=" AND `".mTABLE."`.`Delete_".md5("kDelete")."` IS NULL";
        }elseif(isset($_SESSION["ADP"][CCTRL]) && $_SESSION["ADP"][CCTRL]["display"]==-1){
            $configs["strWhere"].=" AND `".mTABLE."`.`Delete_".md5("kDelete")."` IS NOT NULL";
        }
        $configs["strOrderBy"]=" ORDER BY `Insert_".md5("kInsert")."` DESC";
        $configs["fields"]=array(
            );
        $configs["filterfields"]=array(
            "Title",
            "Alias"
        );
        $this->init($configs);
        return $this->Binding(true);
    }
    
}
?>
